package com.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class BaseDao {
   private  static SqlSessionFactory sessionFactory = null;
    static {
       try {
           InputStream resourceAsStream = Resources.getResourceAsStream("mybaits-config.xml");
            sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);

       }catch (Exception e){
           e.printStackTrace();
       }
    }

    //通用的查询
    public static SqlSession baseSession(){
        SqlSession sqlSession = sessionFactory.openSession(true);
        return sqlSession;
    }


}
